package com.qyhl.shop.shop;

import android.annotation.SuppressLint;
import android.graphics.Rect;
import android.os.Build;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.ViewFlipper;

import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
import androidx.viewpager.widget.ViewPager;

import com.alibaba.android.arouter.launcher.ARouter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.makeramen.roundedimageview.RoundedImageView;
import com.qyhl.shop.R;
import com.qyhl.shop.R2;
import com.qyhl.shop.view.MSwipeRefreshLayout;
import com.qyhl.shop.view.MyIconModel;
import com.qyhl.shop.view.PageGridView;
import com.qyhl.webtv.basiclib.base.BaseFragment;
import com.qyhl.webtv.commonlib.constant.ARouterPathConstant;
import com.qyhl.webtv.commonlib.entity.shop.ShopAdvBean;
import com.qyhl.webtv.commonlib.entity.shop.ShopAdvSpaceBean;
import com.qyhl.webtv.commonlib.entity.shop.ShopMessageBean;
import com.qyhl.webtv.commonlib.entity.shop.ShopTypeBean;
import com.qyhl.webtv.commonlib.utils.ResizableImageView;
import com.qyhl.webtv.commonlib.utils.action.ActionConstant;
import com.qyhl.webtv.commonlib.utils.action.ActionLogUtils;
import com.qyhl.webtv.commonlib.utils.router.RouterManager;
import com.stx.xhb.androidx.XBanner;
import com.stx.xhb.androidx.transformers.Transformer;
import com.weavey.loading.lib.LoadingLayout;
import com.zhy.adapter.recyclerview.CommonAdapter;
import com.zhy.adapter.recyclerview.MultiItemTypeAdapter;
import com.zhy.adapter.recyclerview.base.ViewHolder;
import com.zhy.adapter.recyclerview.wrapper.HeaderAndFooterWrapper;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.OnClick;

@SuppressLint("NonConstantResourceId")
public class ShopHomeFragment extends BaseFragment implements ShopHomeContract.ShopHomeView {
    @BindView(R2.id.title)
    TextView title;
    @BindView(R2.id.text_adv_recycler)
    RecyclerView textAdvRecycler;
    @BindView(R2.id.refresh)
    MSwipeRefreshLayout refresh;
    @BindView(R2.id.load_mask)
    LoadingLayout loadMask;

    XBanner xBanner;
    RelativeLayout columnLayout;
    TextView textAdvTitle;

    RoundedImageView advOne;
    RoundedImageView advTwo;
    RoundedImageView advThree;
    RoundedImageView advFour;

    LinearLayout pointLayout;
    PageGridView pageGridView;

    ResizableImageView couponBtn;
    ResizableImageView rushPurchaseBtn;
    ResizableImageView newsBtn;

    ViewFlipper messageFlipper;

    private boolean showBanner;

    private boolean showOne;

    private boolean showTwo;

    private boolean showThree;

    private boolean showTxtAdv;

    private ShopHomePresenter mPresenter;

    private List<ShopTypeBean> typeList = new ArrayList<>();

    private CommonAdapter<ShopAdvBean> textCommonAdapter;
    private List<ShopAdvBean> textAdvList = new ArrayList<>();

    private List<ShopAdvBean> bannerList = new ArrayList<>();

    private List<ShopAdvBean> carouselList = new ArrayList<>();

    private List<ShopAdvBean> spaceOneList = new ArrayList<>();

    private List<ShopAdvBean> spaceTwoList = new ArrayList<>();

    private List<ShopAdvBean> spaceThreeList = new ArrayList<>();

    private RequestOptions options;

    private boolean isFromActivity;

    private String titleName;

    private ImageView[] points;//动态创建滑动指示器

    private HeaderAndFooterWrapper<ShopAdvBean> headerAndFooterWrapper;

    private LinearLayoutManager linearLayoutManager;

    public void setTitleName(String titleName) {
        this.titleName = titleName;
    }

    public void setFromActivity(boolean fromActivity) {
        isFromActivity = fromActivity;
    }

    public static ShopHomeFragment newInstance(boolean isFromActivity, String title) {
        ShopHomeFragment fragment = new ShopHomeFragment();
        fragment.setFromActivity(isFromActivity);
        fragment.setTitleName(title);
        return fragment;
    }

    @Override
    protected View createView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        return inflater.inflate(R.layout.shop_fragment_home2, null);
    }

    @Override
    protected void create() {
        loadMask.setStatus(LoadingLayout.Loading);
        options = new RequestOptions().error(R.drawable.cover_normal_default).placeholder(R.drawable.cover_normal_default);

        mPresenter = new ShopHomePresenter(this);

        title.setText(titleName);

        refresh.setColorSchemeResources(R.color.global_base_40per, R.color.global_base);

        textAdvRecycler.setLayoutManager(linearLayoutManager = new LinearLayoutManager(getContext()));
        textCommonAdapter = new CommonAdapter<ShopAdvBean>(getContext(), R.layout.shop_item_home_text_adv, textAdvList) {
            @Override
            protected void convert(ViewHolder holder, ShopAdvBean shopAdvBean, int position) {
                holder.setText(R.id.name, shopAdvBean.getShopName());

                holder.setText(R.id.message, shopAdvBean.getContent());
            }
        };
        View headView = LayoutInflater.from(getContext()).inflate(R.layout.shop_home_header_layout, null);
        View footView = LayoutInflater.from(getContext()).inflate(R.layout.shop_home_footer_layout, null);
        xBanner = headView.findViewById(R.id.xBanner);
        textAdvTitle = headView.findViewById(R.id.text_adv_title);
        pointLayout = headView.findViewById(R.id.point_layout);
        newsBtn = headView.findViewById(R.id.news_btn);
        couponBtn = headView.findViewById(R.id.coupon_btn);
        rushPurchaseBtn = headView.findViewById(R.id.rush_purchase_btn);
        messageFlipper = headView.findViewById(R.id.view_flipper);

        pageGridView = footView.findViewById(R.id.pager_layout);
        columnLayout = footView.findViewById(R.id.column_layout);
        advOne = footView.findViewById(R.id.adv_one);
        advTwo = footView.findViewById(R.id.adv_two);
        advThree = footView.findViewById(R.id.adv_three);
        advFour = footView.findViewById(R.id.adv_four);

        headerAndFooterWrapper = new HeaderAndFooterWrapper<>(textCommonAdapter);
        headerAndFooterWrapper.addHeaderView(headView);
        headerAndFooterWrapper.addFootView(footView);
        textAdvRecycler.setAdapter(headerAndFooterWrapper);

        mPresenter.getAdvList();
    }

    @Override
    protected void setListener() {
        advOne.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (bannerList != null && bannerList.size() > 0) {
                    advSkip(bannerList.get(0));
                }
            }
        });

        advTwo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (spaceOneList != null && spaceOneList.size() > 0) {
                    advSkip(spaceOneList.get(0));
                }
            }
        });

        advThree.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (spaceTwoList != null && spaceTwoList.size() > 0) {
                    advSkip(spaceTwoList.get(0));
                }
            }
        });

        advFour.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (bannerList != null && bannerList.size() > 0) {
                    advSkip(bannerList.get(0));
                }
            }
        });

        newsBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RouterManager.router(ARouterPathConstant.SHOP_NEWS_LIST);
            }
        });

        couponBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                ARouter.getInstance()
                        .build(ARouterPathConstant.SHOP_COUPON_LIST)
                        .withString("title", "福利中心")
                        .navigation();
            }
        });

        rushPurchaseBtn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                RouterManager.router(ARouterPathConstant.SHOP_RUSH_PURCHASE_LIST);
            }
        });

        refresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
            @Override
            public void onRefresh() {
                mPresenter.getAdvList();
            }
        });

        loadMask.setOnReloadListener(new LoadingLayout.OnReloadListener() {
            @Override
            public void onReload(View v) {
                loadMask.setReloadButtonText("加载中...");
                mPresenter.getAdvList();
            }
        });

        pageGridView.setOnItemClickListener(new PageGridView.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                ARouter.getInstance()
                        .build(ARouterPathConstant.SHOP_SHOP_LIST)
                        .withInt("typeId", typeList.get(position).getId())
                        .withString("title", typeList.get(position).getName())
                        .navigation();
            }
        });

        textCommonAdapter.setOnItemClickListener(new MultiItemTypeAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                advSkip(textAdvList.get(i - 1));
            }

            @Override
            public boolean onItemLongClick(View view, RecyclerView.ViewHolder viewHolder, int i) {
                return false;
            }
        });

        xBanner.setOnItemClickListener(new XBanner.OnItemClickListener() {
            @Override
            public void onItemClick(XBanner banner, Object model, View view, int position) {
                advSkip(carouselList.get(position));
            }
        });

        //广告浏览
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            textAdvRecycler.setOnScrollChangeListener(new View.OnScrollChangeListener() {
                @Override
                public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                    if (isVisibleToUser(advOne)) {
                        if (!showBanner) {
                            showBanner = true;
                            if (bannerList != null && bannerList.size() > 0) {
                                ActionLogUtils.getInstance().onEvent(ActionConstant.ADV_BROWSE, bannerList.get(0).getAdvertiseSpaceId(), bannerList.get(0).getId());
                            }
                        }
                    } else {
                        showBanner = false;
                    }

                    if (isVisibleToUser(advTwo)) {
                        if (!showOne) {
                            showOne = true;
                            if (spaceOneList != null && spaceOneList.size() > 0) {
                                ActionLogUtils.getInstance().onEvent(ActionConstant.ADV_BROWSE, spaceOneList.get(0).getAdvertiseSpaceId(), spaceOneList.get(0).getId());
                            }
                        }
                    } else {
                        showOne = false;
                    }

                    if (isVisibleToUser(advThree)) {
                        if (!showTwo) {
                            showTwo = true;
                            if (spaceTwoList != null && spaceTwoList.size() > 0) {
                                ActionLogUtils.getInstance().onEvent(ActionConstant.ADV_BROWSE, spaceTwoList.get(0).getAdvertiseSpaceId(), spaceTwoList.get(0).getId());
                            }
                        }
                    } else {
                        showTwo = false;
                    }

                    if (isVisibleToUser(advFour)) {
                        if (!showThree) {
                            showThree = true;
                            if (spaceThreeList != null && spaceThreeList.size() > 0) {
                                ActionLogUtils.getInstance().onEvent(ActionConstant.ADV_BROWSE, spaceThreeList.get(0).getAdvertiseSpaceId(), spaceThreeList.get(0).getId());
                            }
                        }
                    } else {
                        showThree = false;
                    }

                    if (isVisibleToUser(textAdvRecycler)) {
                        if (!showTxtAdv) {
                            showTxtAdv = true;
                            for (int i = 0; i < textAdvList.size(); i++) {
                                ActionLogUtils.getInstance().onEvent(ActionConstant.ADV_BROWSE, textAdvList.get(i).getAdvertiseSpaceId(), textAdvList.get(i).getId());
                            }
                        }
                    } else {
                        showTxtAdv = false;
                    }
                }
            });
        }
    }

    private boolean isVisibleToUser(View view) {
        Rect scrollBounds = new Rect();
        view.getHitRect(scrollBounds);
        return view.getLocalVisibleRect(scrollBounds);
    }

    //设置滑动指示器
    private void setIndicator(int position) {
        for (int i = 0; i < points.length; i++) {
            if (i == position) {
                points[i].setImageResource(R.drawable.shop_home_banner_point_on);
            } else {
                points[i].setImageResource(R.drawable.shop_home_banner_point_off);
            }
        }
    }

    @Override
    protected void onFirstVisible() {

    }

    @Override
    protected void onVisible() {

    }

    @Override
    protected void onHide() {

    }

    @OnClick({R2.id.shop_center_btn, R2.id.search_btn, R2.id.shop_settled_btn})
    public void onClick(View view) {
        int viewId = view.getId();
        if (viewId == R.id.shop_center_btn) {
            RouterManager.routerLoginInterceptor(getContext(), ARouterPathConstant.SHOP_CENTER);
        } else if (viewId == R.id.search_btn) {
            ARouter.getInstance()
                    .build(ARouterPathConstant.SHOP_SEARCH)
                    .navigation();
        } else if (viewId == R.id.shop_settled_btn) {
            Bundle bundle = new Bundle();
            bundle.putString("url", "http://wxshare.i2863.com/shopDetail/shopPage.html");
            RouterManager.router(ARouterPathConstant.SHOP_SETTLED, bundle);
        }
    }

    private void advSkip(ShopAdvBean bean) {
        //点击统计
        ActionLogUtils.getInstance().onEvent(ActionConstant.ADV_CLICK, bean.getAdvertiseSpaceId(), bean.getId());
        if (bean.getShopCouponId() == 0) {
            if (bean.getShopId() != 0) {
                ARouter.getInstance()
                        .build(ARouterPathConstant.SHOP_SHOP_DETAIL)
                        .withInt("shopId", bean.getShopId())
                        .navigation();
                ActionLogUtils.getInstance().onEvent(ActionConstant.SHOP_FROM_ADV, bean.getShopId());
            }
        } else {
            if (bean.getId() != 0) {
                ARouter.getInstance()
                        .build(ARouterPathConstant.SHOP_COUPON_ADV)
                        .withString("title", bean.getTitle())
                        .withInt("advId", bean.getId())
                        .withBoolean("isAdv",true)
                        .navigation();
            }
        }
    }

    @Override
    public void setAdvList(List<ShopAdvSpaceBean> beanList) {
        carouselList.clear();
        textAdvList.clear();
        bannerList.clear();
        spaceOneList.clear();
        spaceTwoList.clear();
        spaceThreeList.clear();
        String carouseDefault = "";
        String bannerDefault = "";
        String oneDefault = "";
        String twoDefault = "";
        String threeDefault = "";
        for (int i = 0; i < beanList.size(); i++) {
            switch (beanList.get(i).getCode()) {
                case "carousel"://轮播
                    carouselList.addAll(beanList.get(i).getAdvertisePutDtoList());
                    carouseDefault = beanList.get(i).getDefaultImageUrl();
                    break;
                case "news"://消息
                    textAdvList.addAll(beanList.get(i).getAdvertisePutDtoList());
                    break;
                case "banner"://banner
                    bannerList.addAll(beanList.get(i).getAdvertisePutDtoList());
                    bannerDefault = beanList.get(i).getDefaultImageUrl();
                    break;
                case "largePic1"://大图1
                    spaceOneList.addAll(beanList.get(i).getAdvertisePutDtoList());
                    oneDefault = beanList.get(i).getDefaultImageUrl();
                    break;
                case "largePic2"://大图2
                    spaceTwoList.addAll(beanList.get(i).getAdvertisePutDtoList());
                    twoDefault = beanList.get(i).getDefaultImageUrl();
                    break;
                case "largePic3"://大图3
                    spaceThreeList.addAll(beanList.get(i).getAdvertisePutDtoList());
                    threeDefault = beanList.get(i).getDefaultImageUrl();
                    break;
            }
        }

        if (carouselList.size() < 1) {
            carouselList.add(new ShopAdvBean("", carouseDefault));
        }

        if (textAdvList != null && textAdvList.size() > 0) {
            textAdvTitle.setVisibility(View.VISIBLE);
        } else {
            textAdvTitle.setVisibility(View.GONE);
        }

        xBanner.setPageTransformer(Transformer.Default);
        xBanner.setBannerData(R.layout.shop_item_home_banner, carouselList);
        xBanner.loadImage(new XBanner.XBannerAdapter() {
            @Override
            public void loadBanner(XBanner banner, Object model, View view, int position) {
                RoundedImageView bannerCover = view.findViewById(R.id.cover);
                TextView title = view.findViewById(R.id.title);
                title.setText(((ShopAdvBean) model).getTitle());
                Glide.with(ShopHomeFragment.this)
                        .load(((ShopAdvBean) model).getImageUrl())
                        .apply(new RequestOptions().placeholder(R.drawable.cover_normal_default).error(R.drawable.cover_normal_default))
                        .into(bannerCover);
            }
        });
        pointLayout.removeAllViews();
        //滑动指示器
        try {
            points = new ImageView[carouselList.size()];
            if (points.length < 2) {
                pointLayout.setVisibility(View.GONE);
            } else {
                for (int i = 0; i < carouselList.size(); i++) {
                    points[i] = new ImageView(getActivity());
                    if (i == 0) {
                        points[i].setImageResource(R.drawable.shop_home_banner_point_on);
                    } else {
                        points[i].setImageResource(R.drawable.shop_home_banner_point_off);
                    }
                    points[i].setPadding(0, 0, 0, 0);
                    pointLayout.addView(points[i]);
                }

                xBanner.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                    @Override
                    public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                    }

                    @Override
                    public void onPageSelected(int position) {
                        //浏览统计
                        ActionLogUtils.getInstance().onEvent(ActionConstant.ADV_BROWSE, carouselList.get(position).getAdvertiseSpaceId(), carouselList.get(position).getId());
                        setIndicator(position);
                    }

                    @Override
                    public void onPageScrollStateChanged(int state) {

                    }
                });
            }
        } catch (Exception e) {
            e.printStackTrace();
        }


        if (bannerList != null && bannerList.size() > 0) {
            Glide.with(ShopHomeFragment.this)
                    .load(bannerList.get(0).getImageUrl())
                    .apply(options)
                    .into(advOne);
        } else {
            Glide.with(ShopHomeFragment.this)
                    .load(bannerDefault)
                    .apply(options)
                    .into(advOne);
        }

        if (spaceOneList != null && spaceOneList.size() > 0) {
            Glide.with(ShopHomeFragment.this)
                    .load(spaceOneList.get(0).getImageUrl())
                    .apply(options)
                    .into(advTwo);
        } else {
            Glide.with(ShopHomeFragment.this)
                    .load(oneDefault)
                    .apply(options)
                    .into(advTwo);
        }

        if (spaceTwoList != null && spaceTwoList.size() > 0) {
            Glide.with(ShopHomeFragment.this)
                    .load(spaceTwoList.get(0).getImageUrl())
                    .apply(options)
                    .into(advThree);
        } else {
            Glide.with(ShopHomeFragment.this)
                    .load(twoDefault)
                    .apply(options)
                    .into(advThree);
        }

        if (spaceThreeList != null && spaceThreeList.size() > 0) {
            Glide.with(ShopHomeFragment.this)
                    .load(spaceThreeList.get(0).getImageUrl())
                    .apply(options)
                    .into(advFour);
        } else {
            Glide.with(ShopHomeFragment.this)
                    .load(threeDefault)
                    .apply(options)
                    .into(advFour);
        }


        mPresenter.getShopTypeList();
    }

    @Override
    public void setShopTypeList(List<ShopTypeBean> beanList) {
        refresh.setRefreshing(false);
        loadMask.setStatus(LoadingLayout.Success);
        loadMask.setReloadButtonText("点击重试~");
        typeList = beanList;
        List<MyIconModel> mList = new ArrayList<>();
        if (typeList != null && typeList.size() > 0) {
            columnLayout.setVisibility(View.VISIBLE);
            for (int i = 0; i < beanList.size(); i++) {
                mList.add(new MyIconModel(beanList.get(i).getName(), getContext(), beanList.get(i).getImageUrl()));
            }
            pageGridView.setData(mList);

        } else {
            columnLayout.setVisibility(View.GONE);
        }

        mPresenter.getMessage();
    }

    @Override
    public void setMessage(List<ShopMessageBean> beanList) {
        if (beanList != null && beanList.size() > 0) {
            messageFlipper.setVisibility(View.VISIBLE);

            messageFlipper.removeAllViews();
            for (int i = 0; i < beanList.size(); i++) {
                View view = getLayoutInflater().inflate(R.layout.shop_item_home_message_flipper, null);
                RoundedImageView cover = view.findViewById(R.id.cover);
                TextView title = view.findViewById(R.id.title);
                TextView tips = view.findViewById(R.id.tips);
                TextView enterBtn = view.findViewById(R.id.enter_btn);

                Glide.with(ShopHomeFragment.this)
                        .load(beanList.get(i).getShopPic())
                        .apply(new RequestOptions().error(R.drawable.cover_normal_default).placeholder(R.drawable.cover_normal_default))
                        .into(cover);

                title.setText(beanList.get(i).getShopName());

                int finalI = i;
                title.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ARouter.getInstance()
                                .build(ARouterPathConstant.SHOP_SHOP_DETAIL)
                                .withInt("shopId", beanList.get(finalI).getShopId())
                                .navigation();
                    }
                });

                switch (beanList.get(i).getMsgType()) {
                    case 1:
                        tips.setText("入驻成功");
                        enterBtn.setText("立即入驻");

                        enterBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                Bundle bundle = new Bundle();
                                bundle.putString("url", "http://wxshare.i2863.com/shopDetail/shopPage.html");
                                RouterManager.router(ARouterPathConstant.SHOP_SETTLED, bundle);
                            }
                        });
                        break;
                    case 2:
                        tips.setText("上新折扣券");
                        enterBtn.setText("立即抢");

                        enterBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ARouter.getInstance()
                                        .build(ARouterPathConstant.SHOP_COUPON_ADV)
                                        .withString("title","折扣券")
                                        .withInt("advId", beanList.get(finalI).getCouponId())
                                        .withBoolean("isAdv",false)
                                        .navigation();
                            }
                        });
                        break;
                    case 3:
                        tips.setText("上新满减券");
                        enterBtn.setText("立即抢");

                        enterBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ARouter.getInstance()
                                        .build(ARouterPathConstant.SHOP_COUPON_ADV)
                                        .withString("title","折扣券")
                                        .withInt("advId", beanList.get(finalI).getCouponId())
                                        .withBoolean("isAdv",false)
                                        .navigation();
                            }
                        });
                        break;
                    case 4:
                        tips.setText("上新“限时抢”");
                        enterBtn.setText("立即抢");

                        enterBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ARouter.getInstance()
                                        .build(ARouterPathConstant.SHOP_RUSH_PURCHASE_DETAIL)
                                        .withInt("id", beanList.get(finalI).getGiftId())
                                        .navigation();
                            }
                        });
                        break;
                    case 5:
                        tips.setText("橱窗上新");
                        enterBtn.setText("去看看");

                        enterBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ARouter.getInstance()
                                        .build(ARouterPathConstant.SHOP_SHOWCASE_DETAIL)
                                        .withInt("itemId", beanList.get(finalI).getItemId())
                                        .navigation();
                            }
                        });
                        break;
                    case 6:
                        tips.setText("上新“新鲜事”");
                        enterBtn.setText("去看看");

                        enterBtn.setOnClickListener(new View.OnClickListener() {
                            @Override
                            public void onClick(View v) {
                                ARouter.getInstance()
                                        .build(ARouterPathConstant.SHOP_SHOP_DETAIL)
                                        .withInt("shopId", beanList.get(finalI).getShopId())
                                        .navigation();
                            }
                        });
                        break;
                }

                messageFlipper.addView(view);
            }
            messageFlipper.setFlipInterval(3000);
            if (beanList.size() != 1) {
                messageFlipper.startFlipping();
            }
        } else {
            messageFlipper.setVisibility(View.GONE);
        }

        headerAndFooterWrapper.notifyDataSetChanged();

       textAdvRecycler.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
           @Override
           public void onGlobalLayout() {
               textAdvRecycler.stopScroll();
           }
       });
    }

    @Override
    public void setError(String msg) {
        refresh.setRefreshing(false);
        loadMask.setStatus(LoadingLayout.Error);
        loadMask.setErrorText(msg);
        loadMask.setReloadButtonText("点击重试~");
    }
}
